﻿using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using LaserMark.DataAccess.Models;
using LaserMark.DataAccess.Service;

namespace LaserMark.Components.Components;

public partial class Photoelectricity
{
    private PhotoelectricitySetting? Model = new();

    [Inject]
    [NotNull]
    private IPhotoelectricityService? Service { get; set; }


    [Inject]
    [NotNull]
    private ISecretService? SecretService { get; set; }

    [NotNull]
    [CascadingParameter]
    private Func<Task>? ColseAsync { get; set; }

    [NotNull]
    private ValidateForm? ValidateForm { get; set; }

    /// <summary>
    /// 
    /// z</summary>
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        Model = await Service.Get();
    }

    private IEnumerable<SelectedItem>? Items { get; set; } = new List<SelectedItem>()
    {
        new SelectedItem("0", "是"),
        new SelectedItem("1", "否")
    };

    private IEnumerable<SelectedItem>? TypeItems { get; set; } = new List<SelectedItem>()
    {
        new SelectedItem("0", "光电扫描"),
        new SelectedItem("1", "机械定位")
    };

    private async Task<bool> OnSave(string password)
    {
        var ret = ValidateForm.Validate();
        var res = await SecretService.GetSecret("Customer", password);
        if (res)
        {
            return await Service.Update(Model);
        }
        else
        {
            return false;
        }
    }
}
